package t2h.gui;

import com.sun.lwuit.Command;
import com.sun.lwuit.Container;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.plaf.UIManager;

public abstract class Screen {
	
    public abstract String getName();
	
	public final void run(final Command backCommand, ActionListener commandListener, final Container demoPanel) {
		final Form demoForm = new Form(getName());
        demoForm.addCommand(new Command("Help") {
            public void actionPerformed(ActionEvent evt) {
                Form helpForm = new Form("Help");
                Label lbAbout = new Label("Nhóm thực hiện:");
                Label mem1 = new Label("- 09520318: Nguyễn Minh Trí");
                Label mem2 = new Label("- 09520114: Hoàng Anh Hùng");
                Label mem3 = new Label("- 09520383: Phan Tấn Tài");
                helpForm.addComponent(lbAbout);
                helpForm.addComponent(mem1);
                helpForm.addComponent(mem2);
                helpForm.addComponent(mem3);
                //helpForm.setLayout(new BorderLayout());
                //TextArea helpText = new TextArea(getHelpImpl(), 5, 10);
                //helpText.setEditable(false);
                //helpForm.setScrollable(false);
                //helpForm.addComponent(BorderLayout.CENTER, helpText);
                Command c = new Command("Back") {
                    public void actionPerformed(ActionEvent evt) {
                        if(demoPanel != null) {
                            demoPanel.replace(demoPanel.getComponentAt(0), demoForm, UIManager.getInstance().getLookAndFeel().getDefaultFormTransitionOut().copy(true));
                        } else {
                            demoForm.showBack();
                        }
                    }
                };
                helpForm.addCommand(c);
                helpForm.setBackCommand(c);
                if(demoPanel != null) {
                    demoPanel.replace(demoPanel.getComponentAt(0), helpForm, UIManager.getInstance().getLookAndFeel().getDefaultFormTransitionOut());
                } else {
                    helpForm.show();
                }
            }
        });
               
        if(demoPanel == null) {
            demoForm.addCommand(backCommand);
            demoForm.setBackCommand(backCommand);
        }
        demoForm.addCommandListener(commandListener);
        execute(demoForm);
        /*if(demoPanel != null) {
            if(Display.getInstance().isPortrait()) {
                demoForm.addCommand(ScreenMain.showDemosCommand, 1);
            }
            demoPanel.removeAll();
            demoPanel.addComponent(BorderLayout.CENTER, demoForm);
            demoPanel.revalidate();
        } else {
            demoForm.show();
        }*/
        demoForm.show();
	}
	
	protected final void execute(Form f) {
        //executeDemo(f.getContentPane());
		executeDemo(f);
    }
	
	//protected abstract void executeDemo(Container f);
	protected abstract void executeDemo(Form f);
	public void cleanup() {
    }
}
